package edu.scau.hot.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.scau.hot.entity.HotRoom;
import edu.scau.hot.service.IHotRoomService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (HotRoom)表控制层
 *
 * @author PaperEasyCode
 * @since 2022-02-28 21:55:09
 */
@RestController
@RequestMapping("hotRoom")
public class HotRoomController{
    /**
     * 服务对象
     */
    @Resource
    private IHotRoomService hotRoomService;

    /**
     * 分页查询
     *
     * @param pageNum  起始页
     * @param pageSize 每页数据大小
     * @param hotRoom  筛选条件
     * @return 查询结果
     */
    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize,HotRoom hotRoom) {
        PageHelper.startPage(pageNum,pageSize);
        List<HotRoom> list = hotRoomService.queryAll(hotRoom);
        return new PageInfo(list);
    }

    /**
     * 查询所有数据
     *
     * @param hotRoom 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<HotRoom>> queryAll(HotRoom hotRoom) {
        return ResponseEntity.ok(this.hotRoomService.queryAll(hotRoom));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<HotRoom> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.hotRoomService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param hotRoom 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<HotRoom> add(@RequestBody HotRoom hotRoom) {
        return ResponseEntity.ok(this.hotRoomService.insert(hotRoom));
    }

    /**
     * 编辑数据
     *
     * @param hotRoom 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<HotRoom> edit(@RequestBody HotRoom hotRoom) {
        return ResponseEntity.ok(this.hotRoomService.update(hotRoom));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.hotRoomService.deleteById(id));
    }

}

